<?php
/* SVN FILE: $Id: cp_skin_plugins.php 257 2010-01-19 21:50:13Z supersmashbrothers $ */
/**
* ibMarket 2
* IP.Board 3.0
* ibMarket ACP plugins html
*
* @author $Author: supersmashbrothers $
* @copyright $Copyright$
* @version $Revision: 257 $
* @lastrevision $Date: 2010-01-19 21:50:13 +0000 (Tue, 19 Jan 2010) $
* @modifiedby $LastChangedBy: supersmashbrothers $
* @lastmodified $LastChangedDate: 2010-01-19 21:50:13 +0000 (Tue, 19 Jan 2010) $
* @filesource $URL: http://ipb-ibmarket.googlecode.com/svn/ibmarket2/trunk/admin/applications_addon/other/ibmarket/skin_cp/cp_skin_plugins.php $
*/

class cp_skin_plugins extends output
{

/**
 * Prevent our main destructor being called by this class
 *
 * @access	public
 * @return	void
 */
public function __destruct()
{
}

/**
 * Manage Plugins installed and uninstalled
 *
 * @access	public
 * @return	string	HTML
 */
public function managePlugins( array $uninstalledPlugins ) {

$reorder = array();
for($i = 1; $i <= count($this->caches['market_plugin']); $i++)
{
	$reorder[] = array($i,$i);
}

$IPBHTML .= <<<EOF
<div class='section_title'>
	<h2>{$this->lang->words['plugins']}</h2>
</div>

<div id='pluginsInstalled'>
	<form method='post' action='{$this->settings['base_url']}module=plugin&amp;section=reorder' id='pluginReorder'>
		<div class='acp-box'>
			<h3>{$this->lang->words['installed_plugins']}</h3>
			<table width='100%' cellpadding='0' cellspacing='0' border='0' class='alternate_rows'>
				<tr>
					<th style='white-space:nowrap'>{$this->lang->words['plugin']}</th>
					<th style='width:1px;min-width:1%;white-space:nowrap'>{$this->lang->words['enabled']}</th>
					<th style='width:1px;min-width:1%;white-space:nowrap'>{$this->lang->words['order']}</th>
					<th style='width:1px;min-width:1%;white-space:nowrap'>{$this->lang->words['options']}</th>
				</tr>

EOF;
foreach($this->caches['market_plugin'] as $plugin)
{
	$enabled = ( $plugin['enabled'] ) ? 'tick.png' : 'cross.png';
	$order = ipsRegistry::getClass('output')->formDropdown('order['.$plugin['directory'].']', $reorder, $plugin['position']);
	$IPBHTML .= <<<EOF
				<tr>
					<td style='white-space:nowrap'><a href='{$this->settings['base_url']}module=plugin&amp;section=plugin&amp;plugin={$plugin['directory']}'><strong>{$plugin['name']}</strong></a></td>
					<td style='white-space:nowrap'><a href='{$this->settings['base_url']}module=plugin&amp;section=enable&amp;plugin={$plugin['directory']}' title='{$this->lang->words['toggle_app_enabled']}'><img src='{$this->settings['skin_acp_url']}/_newimages/icons/{$enabled}' class='ipd' /></a></td>
					<td style='white-space:nowrap'>{$order}</td>
					<td style='white-space:nowrap'>
							<img class='ipbmenu' id="menu_{$plugin['directory']}" src='{$this->settings['skin_acp_url']}/_newimages/menu_open.png' alt='{$this->lang->words['a_options']}' />
							<ul class='acp-menu' id='menu_{$plugin['directory']}_menucontent'>
								<li class='icon manage'><a href='{$this->settings['base_url']}module=plugin&amp;section=settings&amp;plugin={$plugin['directory']}'>{$this->lang->words['edit_settings']}</a></li>
								<li class='icon edit'><a href='{$this->settings['base_url']}module=plugin&amp;section=permission&amp;plugin={$plugin['directory']}'>{$this->lang->words['edit_permission']}</a></li>
								<li class='icon view'><a href='{$this->settings['base_url']}module=plugin&amp;section=plugin&amp;plugin={$plugin['directory']}'>{$this->lang->words['run_plugin']}</a></li>
								<li class='icon delete'><a href='{$this->settings['base_url']}module=plugin&amp;section=uninstall&amp;plugin={$plugin['directory']}'>{$this->lang->words['uninstall_plugin']}</a></li>
							</ul>
					</td>
				</tr>

EOF;
}
if(count($this->caches['market_plugin']) == 0)
{
	$IPBHTML .= <<<EOF
				<tr>
					<td style='white-space:nowrap; text-align:center' colspan='4'><strong>{$this->lang->words['no_plugins_installed']}</strong></td>
				</tr>

EOF;
}
$IPBHTML .= <<<EOF
			</table>
		</div>
		<div class='acp-actionbar'>
			<div class='centeraction'>
				<input type='submit' value='{$this->lang->words['reorder_plugins']}' class='button primary'>
			</div>
		</div>
	</form>
</div>
<br />
<div id='pluginsUninstalled'>
	<div class='acp-box'>
		<h3>{$this->lang->words['plugins_not_installed']}</h3>
		<table width='100%' cellpadding='0' cellspacing='0' border='0' class='alternate_rows'>
			<tr>
				<th style='white-space:nowrap'>{$this->lang->words['plugin']}/{$this->lang->words['description']}</th>
				<th style='white-space:nowrap'>{$this->lang->words['author']}</th>
				<th style='width:1px;min-width:1%;white-space:nowrap'>{$this->lang->words['options']}</th>
			</tr>

EOF;
foreach($uninstalledPlugins as $directory => $plugin)
{
	$enabled = ( $plugin['enabled'] ) ? 'tick.png' : 'cross.png';
	$IPBHTML .= <<<EOF
			<tr>
				<td style='white-space:nowrap'><strong>{$plugin[0]}</strong><br />{$plugin[1]}</td>
				<td style='white-space:nowrap'>{$plugin[2]}</td>
				<td style='white-space:nowrap;text-align:center'>
					<a href='{$this->settings['base_url']}module=plugin&amp;section=install&amp;plugin={$directory}' style='color:red'>{$this->lang->words['install_plugin']}</a>
					<br />
					<a href='{$this->settings['base_url']}module=plugin&amp;section=uninstall&amp;plugin={$directory}' style='color:red'>{$this->lang->words['force_uninstall']}</a>
				</td>
			</tr>

EOF;
}
if(count($uninstalledPlugins) == 0)
{
	$IPBHTML .= <<<EOF
			<tr>
				<td style='white-space:nowrap; text-align:center' colspan='3'><strong>{$this->lang->words['no_available_plugins_install']}</strong></td>
			</tr>

EOF;
}
$IPBHTML .= <<<EOF
		</table>
	</div>
</div>

EOF;
if( IN_DEV )
{
	$IPBHTML .= <<<EOF
<br />
<div id='plugins_DEV'>
	<div style='text-align:center'>
		<a href='{$this->settings['base_url']}module=plugin&amp;section=tools&amp;do=skin'>Export Skin XML to Plugin directories</a>
		<br />
		<a href='{$this->settings['base_url']}module=plugin&amp;section=tools&amp;do=lang'>Export Language XML to Plugin directories</a>
		<br />
		<a href='{$this->settings['base_url']}module=plugin&amp;section=tools&amp;do=task'>Export Tasks XML to Plugin directories</a>
	</div>
</div>

EOF;
}

return $IPBHTML;
}

/**
 * Edit plugin Settings
 *
 * @access	public
 * @return	string	HTML
 */
public function pluginSettings( array $plugin, admin_settings $pluginSettings = NULL ) {

$name = ipsRegistry::getClass('output')->formInput('name', $plugin['name']);
$IPBHTML .= <<<EOF
<div id='pluginSetting'>
	<div class='acp-box'>
		<h3>{$this->lang->words['plugin_settings']}</h3>
		<ul class='acp-form alternate_rows'>
			<li>
				<label>{$this->lang->words['plugin_name']}</label>
				{$name}
			</li>

EOF;
if($pluginSettings)
{
	$IPBHTML .= $pluginSettings->settingsForm($plugin);
}
$IPBHTML .= <<<EOF
		</ul>
	</div>
</div>

EOF;

return $IPBHTML;
}

/**
 * Edit plugin permissions
 *
 * @access	public
 * @return	string	HTML
 */
public function pluginPermission( array $plugin ) {

$view = ipsRegistry::getClass('output')->formCheckbox('VIEW[-1]', in_array(-1, $plugin['view_permission']));
$use = ipsRegistry::getClass('output')->formCheckbox('USE[-1]', in_array(-1, $plugin['use_permission']));
$IPBHTML .= <<<EOF
<script type='text/javascript' src='{$this->settings['js_app_url']}pluginPermissions.js'></script>
<div id='pluginPermission'>
	<div class='acp-box'>
		<h3>{$this->lang->words['plugin_permissions']}</h3>
		<table width='100%' cellpadding='0' cellspacing='0' border='0' class='alternate_rows'>
			<tr>
				<th style='width:40%; text-align:right'>{$this->lang->words['group_name']}</th>
				<th style='width:30%'>{$this->lang->words['view_plugin']}</th>
				<th style='width:30%'>{$this->lang->words['use_plugin']}</th>
			</tr>
			<tr>
				<td style='text-align:right'>
					<em>{$this->lang->words['global_permission']}</em>
				</td>
				<td>
					<div align="center" style="border: 1px solid rgb(119, 119, 119); background-color: rgb(223, 230, 239);">
						{$view}
					</div>
				</td>
				<td>
					<div align="center" style="border: 1px solid rgb(119, 119, 119); background-color: rgb(245, 205, 205);">
						{$use}
					</div>
				</td>
			</tr>

EOF;
foreach($this->caches['group_cache'] as $group)
{
	$view = ipsRegistry::getClass('output')->formCheckbox('VIEW['.$group['g_id'].']', in_array(-1, $plugin['view_permission']) || in_array($group['g_id'], $plugin['view_permission']));
	$use = ipsRegistry::getClass('output')->formCheckbox('USE['.$group['g_id'].']', in_array(-1, $plugin['use_permission']) || in_array($group['g_id'], $plugin['use_permission']));
	$IPBHTML .= <<<EOF
			<tr class='groupID' id='groupID_{$group['g_id']}'>
				<td style='text-align:right'>
					{$group['prefix']}{$group['g_title']}{$group['suffix']}
					<input type="button" value="+" id="perm_group+_{$group['g_id']}" style='width:27px' />
					<input type="button" value="-" id="perm_group-_{$group['g_id']}" style='width:27px' />
				</td>
				<td>
					<div align="center" style="border: 1px solid rgb(119, 119, 119); background-color: rgb(223, 230, 239);">
						{$view}
					</div>
				</td>
				<td>
					<div align="center" style="border: 1px solid rgb(119, 119, 119); background-color: rgb(245, 205, 205);">
						{$use}
					</div>
				</td>
			</tr>

EOF;
}
$IPBHTML .= <<<EOF
			<tr>
				<td>&nbsp;</td>
				<td style='text-align:center'>
					<input type="button" value="+" id="perm_view+" style='width:27px' />
					<input type="button" value="-" id="perm_view-" style='width:27px' />
				</td>
				<td style='text-align:center'>
					<input type="button" value="+" id="perm_use+" style='width:27px' />
					<input type="button" value="-" id="perm_use-" style='width:27px' />
				</td>
			</tr>
		</table>
	</div>
</div>

EOF;

return $IPBHTML;
}

/**
 * Install Plugin page
 *
 * @access	public
 * @return	string	HTML
 */
public function installPlugin( array $plugin, admin_settings $pluginSettings = NULL ) {

$IPBHTML .= <<<EOF
<div class='section_title'>
	<h2>{$this->lang->words['install_plugin']}</h2>
</div>

<form method='post' action='{$this->settings['base_url']}module=plugin&amp;section=doInstall&amp;plugin={$this->request['plugin']}' id='pluginInstall'>

EOF;
$IPBHTML .= $this->pluginSettings( $plugin, $pluginSettings );
$IPBHTML .= <<<EOF
	<br />

EOF;
$IPBHTML .= $this->pluginPermission( $plugin );
$IPBHTML .= <<<EOF
	<br />
	<div class='acp-actionbar'>
		<div class='centeraction'>
			<input type='submit' value='{$this->lang->words['install_plugin']}' class='button primary'>
		</div>
	</div>
</form>

EOF;

return $IPBHTML;
}

/**
 * Install Plugin finished page
 *
 * @access	public
 * @return	string	HTML
 */
public function pluginInstalled() {

$lang 	= sprintf( $this->lang->words['type__text_finished'], $this->lang->words['type__installation'] );

$IPBHTML .= <<<EOF
<div class='information-box'>
 <h2>{$data['title']} {$text}</h2>
 <p style='font-size:12px'>
 	<br />
 	<strong>{$this->lang->words['plugin_installation']}</strong>
	<br />
	{$this->lang->words['installing_plugin_complete']}
	<br /><br />
	<a href='{$this->settings['base_url']}module=plugin&amp;section=setup'><b>{$this->lang->words['return_manage_plugins']}</b></a>
 </p>
</div>

EOF;

return $IPBHTML;
}

/**
 * Plugin settings page
 *
 * @access	public
 * @return	string	HTML
 */
public function pluginSettingsPage( admin_settings $pluginSettings = NULL ) {

$IPBHTML .= <<<EOF
<div class='section_title'>
	<h2>{$this->lang->words['plugin_settings']}</h2>
</div>

<form method='post' action='{$this->settings['base_url']}module=plugin&amp;section=settings&amp;plugin={$this->request['plugin']}' id='pluginInstall'>

EOF;
$IPBHTML .= $this->pluginSettings( $this->caches['market_plugin'][$this->request['plugin']], $pluginSettings );
$IPBHTML .= <<<EOF
	<br />
	<div class='acp-actionbar'>
		<div class='centeraction'>
			<input type='submit' value='{$this->lang->words['save_settings']}' class='button primary'>
		</div>
	</div>
</form>

EOF;

return $IPBHTML;
}

/**
 * Plugin permission page
 *
 * @access	public
 * @return	string	HTML
 */
public function pluginPermissionPage() {

$IPBHTML .= <<<EOF
<div class='section_title'>
	<h2>{$this->lang->words['plugin_permissions']}</h2>
</div>

<form method='post' action='{$this->settings['base_url']}module=plugin&amp;section=permission&amp;plugin={$this->request['plugin']}' id='pluginInstall'>

EOF;
$IPBHTML .= $this->pluginPermission( $this->caches['market_plugin'][$this->request['plugin']] );
$IPBHTML .= <<<EOF
	<br />
	<div class='acp-actionbar'>
		<div class='centeraction'>
			<input type='submit' value='{$this->lang->words['save_permissions']}' class='button primary'>
		</div>
	</div>
</form>

EOF;

return $IPBHTML;
}

/**
 * Plugin settings page
 *
 * @access	public
 * @return	string	HTML
 */
public function confirmUninstall( array $plugin, array $items) {

$IPBHTML .= <<<EOF
<div class='section_title'>
	<h2>{$this->lang->words['uninstall_plugin']}</h2>
</div>

<form method='post' action='{$this->settings['base_url']}module=plugin&amp;section=uninstall&amp;plugin={$this->request['plugin']}&amp;do=uninstall' id='pluginInstall'>
<div id='pluginSetting'>
	<div class='acp-box'>
		<h3>{$this->lang->words['plugin_settings']}</h3>
		<ul class='acp-form alternate_rows'>
			<li>
				<label>{$this->lang->words['plugin']}</label>
				{$plugin['name']}
			</li>

EOF;
if($items)
{
	$_items = array();
	foreach($items as $item)
	{
		$_items .= $item['item_name'];
	}
	$items = implode(', ', $_items);
	$IPBHTML .= <<<EOF
			<li>
				<label>{$this->lang->words['items_to_remove']}</label>
				{$items}
			</li>

EOF;
}
$IPBHTML .= <<<EOF
		</ul>
	</div>
</div>
	<br />
	<div class='acp-actionbar'>
		<div class='centeraction'>
			<input type='submit' value='{$this->lang->words['uninstall_plugin']}' class='button primary'>
		</div>
	</div>
</form>

EOF;

return $IPBHTML;
}

}